package com.gnerv.sylvanas.framework.plugin.datasource.autoconfigure;

import com.gnerv.sylvanas.framework.plugin.datasource.listener.DatasourceEnvironmentChangeEventListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(value = {FrameworkPluginDatasourceConfigProperties.class})
public class FrameworkPluginDatasourceAutoConfiguration {

    @Bean
    @RefreshScope
    @ConditionalOnClass(name = {"org.springframework.cloud.context.environment.EnvironmentChangeEvent"})
    public DatasourceEnvironmentChangeEventListener datasourceEnvironmentChangeEventListener(){
        return new DatasourceEnvironmentChangeEventListener();
    }

}
